package com.ruoyi.web.controller.channel;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.SysChannel;
import com.ruoyi.system.domain.SysMarket;
import com.ruoyi.system.domain.SysPayload;
import com.ruoyi.system.service.ISysPayloadService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Payload;
import java.util.List;

@RestController
@RequestMapping("/system/payload")
public class PayloadController extends BaseController {
    @Resource
    ISysPayloadService iSysPayloadService;
    /**
     * 获取支付渠道列表
     */
    @PreAuthorize("@ss.hasPermi('system:payload:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPayload payload)
    {
        startPage();
        List<SysMarket> list = iSysPayloadService.selectPayloadList(payload);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('system:payload:query')")
    @GetMapping(value = "/{payloadId}")
    public AjaxResult getInfo(@PathVariable int payloadId)
    {
        return AjaxResult.success(iSysPayloadService.selectPayloadIdById(payloadId));
    }
    /*添加支付渠道*/
    @PreAuthorize("@ss.hasPermi('system:payload:add')")
    @Log(title = "支付渠道管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysPayload syspayload)
    {
        /*channel.setCreateBy(SecurityUtils.getUsername());*/
        return toAjax(iSysPayloadService.insertPayload(syspayload));
    }
    /**
     * 修改支付渠道*/

    @PreAuthorize("@ss.hasPermi('system:channel:edit')")
    @Log(title = "支付渠道管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysPayload syspayload)
    {
        /*channel.setUpdateBy(SecurityUtils.getUsername());*/
        return toAjax(iSysPayloadService.updatePayload(syspayload));
    }
    /**
     * 删除支付渠道*/

    @PreAuthorize("@ss.hasPermi('system:channel:remove')")
    @Log(title = "支付渠道管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{payloadId}")
    public AjaxResult remove(@PathVariable int payloadId)
    {
        return toAjax(iSysPayloadService.deletePayloadById(payloadId));
    }
}
